package top.longmarch.flow.api;

import cn.hutool.core.util.StrUtil;
import top.longmarch.flow.exception.BusinessException;

import java.util.ArrayList;
import java.util.List;

public class ClassBeanUtil {

    public static List<Class<?>> getContextBeanClazzArray(String contextBeans) {
        List<Class<?>> contextBeanClazzList = new ArrayList<>();
        if (StrUtil.isBlank(contextBeans)) {
            return contextBeanClazzList;
        }
        String[] contextBeanSplit = contextBeans.split(",");

        for (String bean : contextBeanSplit) {
            contextBeanClazzList.add(getContextBeanClazz(bean));
        }
        return contextBeanClazzList;
    }

    public static Class<?> getContextBeanClazz(String contextBean) {
        try {
            return Class.forName(contextBean);
        } catch (ClassNotFoundException e) {
            throw new BusinessException(5000, e.getMessage());
        }
    }

}
